package com.smedi.ismedi.progress.core.port.adapter.persistence.model;


import com.baomidou.mybatisplus.annotation.TableName;
import com.smedi.ismedi.database.starter.model.BasicFieldEntity;
import com.smedi.ismedi.progress.api.dto.request.AttachmentRequest;
import lombok.*;

import java.util.ArrayList;
import java.util.List;


@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@TableName(value = "attachment")
public class AttachmentEntity  extends BasicFieldEntity {

    private String signKey;

    private String fileName;

    private  String fileType;

    private  String tableName;

    private Long relevanceKey;


    /**
     * 构建附件
     * @param tableName 附件数据所属主表
     * @param relevanceKey 主表关联字段
     * @param requests  requests
     * @return List<AttachmentEntity>
     */
    public static List<AttachmentEntity> getAttach(String tableName,Long relevanceKey, List<AttachmentRequest> requests){
        List<AttachmentEntity> att = new ArrayList<>();
        for (AttachmentRequest request : requests) {
            AttachmentEntity build = AttachmentEntity.builder().fileName(request.getFileName())
                    .signKey(request.getSignKey())
                    .tableName(tableName).relevanceKey(relevanceKey).build();
            att.add(build);
        }
        return  att;
    }
}
